<?php 
namespace app\home\model;
use think\Model;
/**
* 
*/
class Category extends Model
{
	
	 public function getchilrenid($cateid){
            $cateres=$this->select();
            $arr=$this->_getchilrenid($cateres,$cateid);
            $arr[]=$cateid;
            $strID=implode(',', $arr);
            return $strID;
        }

        public function _getchilrenid($cateres,$cateid)
        {
            static $arr=array();
            foreach ($cateres as $k => $v) {
                if ($v['pid']==$cateid) {
                    $arr[]=$v['cid'];
                    $this->_getchilrenid($cateres,$v['cid']);
                }
            }
            return $arr;
        }
         public function getparents($cateid){
            $cateres=$this->field('cid,pid,catename')->select();
            $cates=db('category')->field('cid,pid,catename')->find($cateid);//当前分类信息
            $pid=$cates['pid'];
            if ($pid) {
            	$arr=$this->_getparentsid($cateres,$pid);
            }
            
            $arr[]=$cates;

            return $arr;
        }

        public function _getparentsid($cateres,$pid)
        {
            static $arr=array();
            foreach ($cateres as $k => $v) {
                if ($v['cid']==$pid) {
                    $arr[]=$v;
                    $this->_getparentsid($cateres,$v['pid']);
                }
            }
            return $arr;
        }
         public function getCateInfo($cateid){
        $cateInfo=$this->field('catename,keywords,desc')->find($cateid);
        return $cateInfo;
    }

}